from app import db
from app.models.Student import Student


class Sentence(db.Document):
    auth_id = db.StringField()
    admin = db.BooleanField()
    content = db.StringField()
    time = db.FloatField()
    meta = {'collection': 'sentences', 'strict': False}

    @classmethod
    def get_sentence_by_username(cls, auth_id):
        return cls.objects(auth_id=auth_id)

    @classmethod
    def insert_sentence(cls, index, auth_id, admin, content, time):
        return Sentence(index=index, auth_id=auth_id, admin=admin, content=content, time=time).save()

    @classmethod
    def get_talk_list(cls):
        talk_list = Student.get_all()

        def func(x):
            return {
                "name": x['name'],
                "auth_id": x['studentId']
            }

        return list(map(func, talk_list))
